import React from "react";
import { View, ActivityIndicator, AsyncStorage } from "react-native";
import { colors } from "../Style/Colors";
import SplashScreen from "react-native-splash-screen";
import Toast from "react-native-simple-toast";

export class FetchScreen extends React.Component {
  componentDidMount = async () => {
    SplashScreen.hide();
    try {
      const value = await AsyncStorage.getItem("loggedin-user");
      if (value !== null) {
        if (value === "doctor") {
          this.props.navigation.navigate("FetchData");
        } else if (value === "houseman") {
<<<<<<< HEAD
          this.props.navigation.navigate("FetchData");
=======
          this.props.navigation.navigate("HSManDashboard");
>>>>>>> 503b0544130247b48d86f53bc47ed722f01e5c05
        }
      } else {
        this.props.navigation.navigate("Auth");
      }
    } catch (e) {
      Toast.show(e.message);
    }
  };

  render() {
    return (
      <View
        style={{
          flex: 1,
          justifyContent: "center",
          alignItems: "center",
          backgroundColor: colors.whiteColor
        }}
      >
        <ActivityIndicator size="large" color={colors.primaryColor} />
      </View>
    );
  }
}

export default FetchScreen;
